1
|
|
|
var lfm_route = location.origin + location.pathname; |
2
|
|
|
var show_list; |
3
|
|
|
var sort_type = 'alphabetic'; |
4
|
|
|
var multi_selection_enabled = false; |
5
|
|
|
var selected = []; |
6
|
|
|
var items = []; |
7
|
|
|
|
8
|
|
|
$.fn.fab = function (options) { |
9
|
|
|
var menu = this; |
10
|
|
|
menu.addClass('fab-wrapper'); |
11
|
|
|
|
12
|
|
|
var toggler = $('<a>') |
13
|
|
|
.addClass('fab-button fab-toggle') |
14
|
|
|
.append($('<i>').addClass('fas fa-plus')) |
15
|
|
|
.click(function () { |
16
|
|
|
menu.toggleClass('fab-expand'); |
17
|
|
|
}); |
18
|
|
|
|
19
|
|
|
menu.append(toggler); |
20
|
|
|
|
21
|
|
|
options.buttons.forEach(function (button) { |
22
|
|
|
toggler.before( |
23
|
|
|
$('<a>').addClass('fab-button fab-action') |
24
|
|
|
.attr('data-label', button.label) |
25
|
|
|
.attr('id', button.attrs.id) |
26
|
|
|
.append($('<i>').addClass(button.icon)) |
27
|
|
|
.click(function () { |
28
|
|
|
menu.removeClass('fab-expand'); |
29
|
|
|
}) |
30
|
|
|
); |
31
|
|
|
}); |
32
|
|
|
}; |
33
|
|
|
|
34
|
|
|
$(document).ready(function () { |
35
|
|
|
$('#fab').fab({ |
36
|
|
|
buttons: [ |
37
|
|
|
{ |
38
|
|
|
icon: 'fas fa-upload', |
39
|
|
|
label: lang['nav-upload'], |
|
|
|
|
40
|
|
|
attrs: {id: 'upload'} |
41
|
|
|
}, |
42
|
|
|
{ |
43
|
|
|
icon: 'fas fa-folder', |
44
|
|
|
label: lang['nav-new'], |
45
|
|
|
attrs: {id: 'add-folder'} |
46
|
|
|
} |
47
|
|
|
] |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
actions.reverse().forEach(function (action) { |
|
|
|
|
51
|
|
|
$('#nav-buttons > ul').prepend( |
52
|
|
|
$('<li>').addClass('nav-item').append( |
53
|
|
|
$('<a>').addClass('nav-link d-none') |
54
|
|
|
.attr('data-action', action.name) |
55
|
|
|
.attr('data-multiple', action.multiple) |
56
|
|
|
.append($('<i>').addClass('fas fa-fw fa-' + action.icon)) |
57
|
|
|
.append($('<span>').text(action.label)) |
58
|
|
|
) |
59
|
|
|
); |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
sortings.forEach(function (sort) { |
|
|
|
|
63
|
|
|
$('#nav-buttons .dropdown-menu').append( |
64
|
|
|
$('<a>').addClass('dropdown-item').attr('data-sortby', sort.by) |
65
|
|
|
.append($('<i>').addClass('fas fa-fw fa-' + sort.icon)) |
66
|
|
|
.append($('<span>').text(sort.label)) |
67
|
|
|
.click(function() { |
68
|
|
|
sort_type = sort.by; |
69
|
|
|
loadItems(); |
70
|
|
|
}) |
71
|
|
|
); |
72
|
|
|
}); |
73
|
|
|
|
74
|
|
|
loadFolders(); |
75
|
|
|
performLfmRequest('errors') |
76
|
|
|
.done(function (response) { |
77
|
|
|
JSON.parse(response).forEach(function (message) { |
78
|
|
|
$('#alerts').append( |
79
|
|
|
$('<div>').addClass('alert alert-warning') |
80
|
|
|
.append($('<i>').addClass('fas fa-exclamation-circle')) |
81
|
|
|
.append(' ' + message) |
82
|
|
|
); |
83
|
|
|
}); |
84
|
|
|
}); |
85
|
|
|
|
86
|
|
|
$(window).on('dragenter', function(){ |
87
|
|
|
$('#uploadModal').modal('show'); |
88
|
|
|
}); |
89
|
|
|
|
90
|
|
|
if (usingWysiwygEditor()) { |
91
|
|
|
$('#multi_selection_toggle').hide(); |
92
|
|
|
} |
93
|
|
|
}); |
94
|
|
|
|
95
|
|
|
// ====================== |
96
|
|
|
// == Navbar actions == |
97
|
|
|
// ====================== |
98
|
|
|
|
99
|
|
|
$('#multi_selection_toggle').click(function () { |
100
|
|
|
multi_selection_enabled = !multi_selection_enabled; |
101
|
|
|
|
102
|
|
|
$('#multi_selection_toggle i') |
103
|
|
|
.toggleClass('fa-times', multi_selection_enabled) |
104
|
|
|
.toggleClass('fa-check-double', !multi_selection_enabled); |
105
|
|
|
|
106
|
|
|
if (!multi_selection_enabled) { |
107
|
|
|
clearSelected(); |
108
|
|
|
} |
109
|
|
|
}); |
110
|
|
|
|
111
|
|
|
$('#to-previous').click(function () { |
112
|
|
|
var previous_dir = getPreviousDir(); |
113
|
|
|
if (previous_dir == '') return; |
|
|
|
|
114
|
|
|
goTo(previous_dir); |
115
|
|
|
}); |
116
|
|
|
|
117
|
|
|
function toggleMobileTree(should_display) { |
118
|
|
|
if (should_display === undefined) { |
119
|
|
|
should_display = !$('#tree').hasClass('in'); |
120
|
|
|
} |
121
|
|
|
$('#tree').toggleClass('in', should_display); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$('#show_tree').click(function (e) { |
|
|
|
|
125
|
|
|
toggleMobileTree(); |
126
|
|
|
}); |
127
|
|
|
|
128
|
|
|
$('#main').click(function (e) { |
|
|
|
|
129
|
|
|
if ($('#tree').hasClass('in')) { |
130
|
|
|
toggleMobileTree(false); |
131
|
|
|
} |
132
|
|
|
}); |
133
|
|
|
|
134
|
|
|
$(document).on('click', '#add-folder', function () { |
135
|
|
|
dialog(lang['message-name'], '', createFolder); |
|
|
|
|
136
|
|
|
}); |
137
|
|
|
|
138
|
|
|
$(document).on('click', '#upload', function () { |
139
|
|
|
$('#uploadModal').modal('show'); |
140
|
|
|
}); |
141
|
|
|
|
142
|
|
|
$(document).on('click', '[data-display]', function() { |
143
|
|
|
show_list = $(this).data('display'); |
144
|
|
|
loadItems(); |
145
|
|
|
}); |
146
|
|
|
|
147
|
|
|
$(document).on('click', '[data-action]', function() { |
148
|
|
|
window[$(this).data('action')]($(this).data('multiple') ? getSelectedItems() : getOneSelectedElement()); |
149
|
|
|
}); |
150
|
|
|
|
151
|
|
|
// ========================== |
152
|
|
|
// == Multiple Selection == |
153
|
|
|
// ========================== |
154
|
|
|
|
155
|
|
|
function toggleSelected (e) { |
156
|
|
|
if (!multi_selection_enabled) { |
157
|
|
|
selected = []; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
var sequence = $(e.target).closest('a').data('id'); |
161
|
|
|
var element_index = selected.indexOf(sequence); |
162
|
|
|
if (element_index === -1) { |
163
|
|
|
selected.push(sequence); |
164
|
|
|
} else { |
165
|
|
|
selected.splice(element_index, 1); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
updateSelectedStyle(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
function clearSelected () { |
172
|
|
|
selected = []; |
173
|
|
|
|
174
|
|
|
multi_selection_enabled = false; |
175
|
|
|
|
176
|
|
|
updateSelectedStyle(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
function updateSelectedStyle() { |
180
|
|
|
items.forEach(function (item, index) { |
181
|
|
|
$('[data-id=' + index + ']') |
182
|
|
|
.find('.square') |
183
|
|
|
.toggleClass('selected', selected.indexOf(index) > -1); |
184
|
|
|
}); |
185
|
|
|
toggleActions(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
function getOneSelectedElement(orderOfItem) { |
189
|
|
|
var index = orderOfItem !== undefined ? orderOfItem : selected[0]; |
190
|
|
|
return items[index]; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
function getSelectedItems() { |
194
|
|
|
return selected.reduce(function (arr_objects, id) { |
195
|
|
|
arr_objects.push(getOneSelectedElement(id)); |
196
|
|
|
return arr_objects |
197
|
|
|
}, []); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
function toggleActions() { |
201
|
|
|
var one_selected = selected.length === 1; |
202
|
|
|
var many_selected = selected.length >= 1; |
203
|
|
|
var only_image = getSelectedItems() |
204
|
|
|
.filter(function (item) { return !item.is_image; }) |
205
|
|
|
.length === 0; |
206
|
|
|
var only_file = getSelectedItems() |
207
|
|
|
.filter(function (item) { return !item.is_file; }) |
208
|
|
|
.length === 0; |
209
|
|
|
|
210
|
|
|
$('[data-action=use]').toggleClass('d-none', !(many_selected && only_file)); |
211
|
|
|
$('[data-action=rename]').toggleClass('d-none', !one_selected); |
212
|
|
|
$('[data-action=preview]').toggleClass('d-none', !(many_selected && only_file)); |
213
|
|
|
$('[data-action=move]').toggleClass('d-none', !many_selected); |
214
|
|
|
$('[data-action=download]').toggleClass('d-none', !(many_selected && only_file)); |
215
|
|
|
$('[data-action=resize]').toggleClass('d-none', !(one_selected && only_image)); |
216
|
|
|
$('[data-action=crop]').toggleClass('d-none', !(one_selected && only_image)); |
217
|
|
|
$('[data-action=trash]').toggleClass('d-none', !many_selected); |
218
|
|
|
$('[data-action=open]').toggleClass('d-none', !one_selected || only_file); |
219
|
|
|
$('#multi_selection_toggle').toggleClass('d-none', usingWysiwygEditor() || !many_selected); |
220
|
|
|
$('#actions').toggleClass('d-none', selected.length === 0); |
221
|
|
|
$('#fab').toggleClass('d-none', selected.length !== 0); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
// ====================== |
225
|
|
|
// == Folder actions == |
226
|
|
|
// ====================== |
227
|
|
|
|
228
|
|
|
$(document).on('click', '#tree a', function (e) { |
229
|
|
|
goTo($(e.target).closest('a').data('path')); |
230
|
|
|
toggleMobileTree(false); |
231
|
|
|
}); |
232
|
|
|
|
233
|
|
|
function goTo(new_dir) { |
234
|
|
|
$('#working_dir').val(new_dir); |
235
|
|
|
loadItems(); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
function getPreviousDir() { |
239
|
|
|
var working_dir = $('#working_dir').val(); |
240
|
|
|
return working_dir.substring(0, working_dir.lastIndexOf('/')); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
function setOpenFolders() { |
244
|
|
|
$('#tree [data-path]').each(function (index, folder) { |
245
|
|
|
// close folders that are not parent |
246
|
|
|
var should_open = ($('#working_dir').val() + '/').startsWith($(folder).data('path') + '/'); |
247
|
|
|
$(folder).children('i') |
248
|
|
|
.toggleClass('fa-folder-open', should_open) |
249
|
|
|
.toggleClass('fa-folder', !should_open); |
250
|
|
|
}); |
251
|
|
|
|
252
|
|
|
$('#tree .nav-item').removeClass('active'); |
253
|
|
|
$('#tree [data-path="' + $('#working_dir').val() + '"]').parent('.nav-item').addClass('active'); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
// ==================== |
257
|
|
|
// == Ajax actions == |
258
|
|
|
// ==================== |
259
|
|
|
|
260
|
|
|
function performLfmRequest(url, parameter, type) { |
261
|
|
|
var data = defaultParameters(); |
262
|
|
|
|
263
|
|
|
if (parameter != null) { |
|
|
|
|
264
|
|
|
$.each(parameter, function (key, value) { |
265
|
|
|
data[key] = value; |
266
|
|
|
}); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
return $.ajax({ |
270
|
|
|
type: 'GET', |
271
|
|
|
beforeSend: function(request) { |
272
|
|
|
var token = getUrlParam('token'); |
273
|
|
|
if (token !== null) { |
274
|
|
|
request.setRequestHeader("Authorization", 'Bearer ' + token); |
275
|
|
|
} |
276
|
|
|
}, |
277
|
|
|
dataType: type || 'text', |
278
|
|
|
url: lfm_route + '/' + url, |
279
|
|
|
data: data, |
280
|
|
|
cache: false |
281
|
|
|
}).fail(function (jqXHR, textStatus, errorThrown) { |
|
|
|
|
282
|
|
|
displayErrorResponse(jqXHR); |
283
|
|
|
}); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
function displayErrorResponse(jqXHR) { |
287
|
|
|
notify('<div style="max-height:50vh;overflow: scroll;">' + jqXHR.responseText + '</div>'); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
var refreshFoldersAndItems = function (data) { |
291
|
|
|
loadFolders(); |
292
|
|
|
if (data != 'OK') { |
293
|
|
|
data = Array.isArray(data) ? data.join('<br/>') : data; |
294
|
|
|
notify(data); |
295
|
|
|
} |
296
|
|
|
}; |
297
|
|
|
|
298
|
|
|
var hideNavAndShowEditor = function (data) { |
299
|
|
|
$('#nav-buttons > ul').addClass('d-none'); |
300
|
|
|
$('#content').html(data).removeClass('preserve_actions_space'); |
301
|
|
|
clearSelected(); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
function loadFolders() { |
305
|
|
|
performLfmRequest('folders', {}, 'html') |
306
|
|
|
.done(function (data) { |
307
|
|
|
$('#tree').html(data); |
308
|
|
|
loadItems(); |
309
|
|
|
}); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
function loadItems() { |
313
|
|
|
loading(true); |
314
|
|
|
performLfmRequest('jsonitems', {show_list: show_list, sort_type: sort_type}, 'html') |
315
|
|
|
.done(function (data) { |
316
|
|
|
selected = []; |
317
|
|
|
var response = JSON.parse(data); |
318
|
|
|
var working_dir = response.working_dir; |
319
|
|
|
items = response.items; |
320
|
|
|
var hasItems = items.length !== 0; |
321
|
|
|
$('#empty').toggleClass('d-none', hasItems); |
322
|
|
|
$('#content').html('').removeAttr('class'); |
323
|
|
|
|
324
|
|
|
if (hasItems) { |
325
|
|
|
$('#content').addClass(response.display).addClass('preserve_actions_space'); |
326
|
|
|
|
327
|
|
|
items.forEach(function (item, index) { |
328
|
|
|
var template = $('#item-template').clone() |
329
|
|
|
.removeAttr('id class') |
330
|
|
|
.attr('data-id', index) |
331
|
|
|
.click(toggleSelected) |
332
|
|
|
.dblclick(function (e) { |
|
|
|
|
333
|
|
|
if (item.is_file) { |
334
|
|
|
use(getSelectedItems()); |
335
|
|
|
} else { |
336
|
|
|
goTo(item.url); |
337
|
|
|
} |
338
|
|
|
}); |
339
|
|
|
|
340
|
|
|
if (item.thumb_url) { |
341
|
|
|
var image = $('<div>').css('background-image', 'url("' + item.thumb_url + '?timestamp=' + item.time + '")'); |
342
|
|
|
} else { |
343
|
|
|
var image = $('<div>').addClass('mime-icon ico-' + item.icon); |
|
|
|
|
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
template.find('.square').append(image); |
347
|
|
|
template.find('.item_name').text(item.name); |
348
|
|
|
template.find('time').text((new Date(item.time * 1000)).toLocaleString()); |
349
|
|
|
|
350
|
|
|
$('#content').append(template); |
351
|
|
|
}); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
$('#nav-buttons > ul').removeClass('d-none'); |
355
|
|
|
|
356
|
|
|
$('#working_dir').val(working_dir); |
357
|
|
|
console.log('Current working_dir : ' + working_dir); |
|
|
|
|
358
|
|
|
var breadcrumbs = []; |
359
|
|
|
var validSegments = working_dir.split('/').filter(function (e) { return e; }); |
360
|
|
|
validSegments.forEach(function (segment, index) { |
361
|
|
|
if (index === 0) { |
362
|
|
|
// set root folder name as the first breadcrumb |
363
|
|
|
breadcrumbs.push($("[data-path='/" + segment + "']").text()); |
364
|
|
|
} else { |
365
|
|
|
breadcrumbs.push(segment); |
366
|
|
|
} |
367
|
|
|
}); |
368
|
|
|
|
369
|
|
|
$('#current_folder').text(breadcrumbs[breadcrumbs.length - 1]); |
370
|
|
|
$('#breadcrumbs > ol').html(''); |
371
|
|
|
breadcrumbs.forEach(function (breadcrumb, index) { |
372
|
|
|
var li = $('<li>').addClass('breadcrumb-item').text(breadcrumb); |
373
|
|
|
|
374
|
|
|
if (index === breadcrumbs.length - 1) { |
375
|
|
|
li.addClass('active').attr('aria-current', 'page'); |
376
|
|
|
} else { |
377
|
|
|
li.click(function () { |
378
|
|
|
// go to corresponding path |
379
|
|
|
goTo('/' + validSegments.slice(0, 1 + index).join('/')); |
380
|
|
|
}); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
$('#breadcrumbs > ol').append(li); |
384
|
|
|
}); |
385
|
|
|
|
386
|
|
|
var atRootFolder = getPreviousDir() == ''; |
387
|
|
|
$('#to-previous').toggleClass('d-none invisible-lg', atRootFolder); |
388
|
|
|
$('#show_tree').toggleClass('d-none', !atRootFolder).toggleClass('d-block', atRootFolder); |
389
|
|
|
setOpenFolders(); |
390
|
|
|
loading(false); |
391
|
|
|
toggleActions(); |
392
|
|
|
}); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
function loading(show_loading) { |
396
|
|
|
$('#loading').toggleClass('d-none', !show_loading); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
function createFolder(folder_name) { |
400
|
|
|
performLfmRequest('newfolder', {name: folder_name}) |
401
|
|
|
.done(refreshFoldersAndItems); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
// ================================== |
405
|
|
|
// == File Actions == |
406
|
|
|
// ================================== |
407
|
|
|
|
408
|
|
|
function rename(item) { |
409
|
|
|
dialog(lang['message-rename'], item.name, function (new_name) { |
|
|
|
|
410
|
|
|
performLfmRequest('rename', { |
411
|
|
|
file: item.name, |
412
|
|
|
new_name: new_name |
413
|
|
|
}).done(refreshFoldersAndItems); |
414
|
|
|
}); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
function trash(items) { |
418
|
|
|
notify(lang['message-delete'], function () { |
|
|
|
|
419
|
|
|
performLfmRequest('delete', { |
420
|
|
|
items: items.map(function (item) { return item.name; }) |
421
|
|
|
}).done(refreshFoldersAndItems) |
422
|
|
|
}); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
function crop(item) { |
426
|
|
|
performLfmRequest('crop', {img: item.name}) |
427
|
|
|
.done(hideNavAndShowEditor); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
function resize(item) { |
431
|
|
|
performLfmRequest('resize', {img: item.name}) |
432
|
|
|
.done(hideNavAndShowEditor); |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
function download(items) { |
436
|
|
|
items.forEach(function (item, index) { |
437
|
|
|
var data = defaultParameters(); |
438
|
|
|
|
439
|
|
|
data['file'] = item.name; |
440
|
|
|
|
441
|
|
|
var token = getUrlParam('token'); |
442
|
|
|
if (token) { |
443
|
|
|
data['token'] = token; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
setTimeout(function () { |
447
|
|
|
location.href = lfm_route + '/download?' + $.param(data); |
448
|
|
|
}, index * 100); |
449
|
|
|
}); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
function open(item) { |
453
|
|
|
goTo(item.url); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
function preview(items) { |
457
|
|
|
var carousel = $('#carouselTemplate').clone().attr('id', 'previewCarousel').removeClass('d-none'); |
458
|
|
|
var imageTemplate = carousel.find('.carousel-item').clone().removeClass('active'); |
459
|
|
|
var indicatorTemplate = carousel.find('.carousel-indicators > li').clone().removeClass('active'); |
460
|
|
|
carousel.children('.carousel-inner').html(''); |
461
|
|
|
carousel.children('.carousel-indicators').html(''); |
462
|
|
|
carousel.children('.carousel-indicators,.carousel-control-prev,.carousel-control-next').toggle(items.length > 1); |
463
|
|
|
|
464
|
|
|
items.forEach(function (item, index) { |
465
|
|
|
var carouselItem = imageTemplate.clone() |
466
|
|
|
.addClass(index === 0 ? 'active' : ''); |
467
|
|
|
|
468
|
|
|
if (item.thumb_url) { |
469
|
|
|
carouselItem.find('.carousel-image').css('background-image', 'url(\'' + item.url + '?timestamp=' + item.time + '\')'); |
470
|
|
|
} else { |
471
|
|
|
carouselItem.find('.carousel-image').css('width', '50vh').append($('<div>').addClass('mime-icon ico-' + item.icon)); |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
carouselItem.find('.carousel-label').attr('target', '_blank').attr('href', item.url) |
475
|
|
|
.append(item.name) |
476
|
|
|
.append($('<i class="fas fa-external-link-alt ml-2"></i>')); |
477
|
|
|
|
478
|
|
|
carousel.children('.carousel-inner').append(carouselItem); |
479
|
|
|
|
480
|
|
|
var carouselIndicator = indicatorTemplate.clone() |
481
|
|
|
.addClass(index === 0 ? 'active' : '') |
482
|
|
|
.attr('data-slide-to', index); |
483
|
|
|
carousel.children('.carousel-indicators').append(carouselIndicator); |
484
|
|
|
}); |
485
|
|
|
|
486
|
|
|
|
487
|
|
|
// carousel swipe control |
488
|
|
|
var touchStartX = null; |
489
|
|
|
|
490
|
|
|
carousel.on('touchstart', function (event) { |
491
|
|
|
var e = event.originalEvent; |
492
|
|
|
if (e.touches.length == 1) { |
|
|
|
|
493
|
|
|
var touch = e.touches[0]; |
494
|
|
|
touchStartX = touch.pageX; |
495
|
|
|
} |
496
|
|
|
}).on('touchmove', function (event) { |
497
|
|
|
var e = event.originalEvent; |
498
|
|
|
if (touchStartX != null) { |
|
|
|
|
499
|
|
|
var touchCurrentX = e.changedTouches[0].pageX; |
500
|
|
|
if ((touchCurrentX - touchStartX) > 60) { |
501
|
|
|
touchStartX = null; |
502
|
|
|
carousel.carousel('prev'); |
503
|
|
|
} else if ((touchStartX - touchCurrentX) > 60) { |
504
|
|
|
touchStartX = null; |
505
|
|
|
carousel.carousel('next'); |
506
|
|
|
} |
507
|
|
|
} |
508
|
|
|
}).on('touchend', function () { |
509
|
|
|
touchStartX = null; |
510
|
|
|
}); |
511
|
|
|
// end carousel swipe control |
512
|
|
|
|
513
|
|
|
notify(carousel); |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
function move(items) { |
517
|
|
|
performLfmRequest('move', { items: items.map(function (item) { return item.name; }) }) |
518
|
|
|
.done(refreshFoldersAndItems); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
function getUrlParam(paramName) { |
522
|
|
|
var reParam = new RegExp('(?:[\?&]|&)' + paramName + '=([^&]+)', 'i'); |
523
|
|
|
var match = window.location.search.match(reParam); |
524
|
|
|
return ( match && match.length > 1 ) ? match[1] : null; |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
function use(items) { |
528
|
|
|
function useTinymce3(url) { |
529
|
|
|
if (!usingTinymce3()) { return; } |
530
|
|
|
|
531
|
|
|
var win = tinyMCEPopup.getWindowArg("window"); |
|
|
|
|
532
|
|
|
win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = url; |
533
|
|
|
if (typeof(win.ImageDialog) != "undefined") { |
534
|
|
|
// Update image dimensions |
535
|
|
|
if (win.ImageDialog.getImageData) { |
536
|
|
|
win.ImageDialog.getImageData(); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
// Preview if necessary |
540
|
|
|
if (win.ImageDialog.showPreviewImage) { |
541
|
|
|
win.ImageDialog.showPreviewImage(url); |
542
|
|
|
} |
543
|
|
|
} |
544
|
|
|
tinyMCEPopup.close(); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
function useTinymce4AndColorbox(url) { |
548
|
|
|
if (!usingTinymce4AndColorbox()) { return; } |
549
|
|
|
|
550
|
|
|
parent.document.getElementById(getUrlParam('field_name')).value = url; |
|
|
|
|
551
|
|
|
|
552
|
|
|
if(typeof parent.tinyMCE !== "undefined") { |
553
|
|
|
parent.tinyMCE.activeEditor.windowManager.close(); |
554
|
|
|
} |
555
|
|
|
if(typeof parent.$.fn.colorbox !== "undefined") { |
556
|
|
|
parent.$.fn.colorbox.close(); |
557
|
|
|
} |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
function useCkeditor3(url) { |
561
|
|
|
if (!usingCkeditor3()) { return; } |
562
|
|
|
|
563
|
|
|
if (window.opener) { |
564
|
|
|
// Popup |
565
|
|
|
window.opener.CKEDITOR.tools.callFunction(getUrlParam('CKEditorFuncNum'), url); |
566
|
|
|
} else { |
567
|
|
|
// Modal (in iframe) |
568
|
|
|
parent.CKEDITOR.tools.callFunction(getUrlParam('CKEditorFuncNum'), url); |
|
|
|
|
569
|
|
|
parent.CKEDITOR.tools.callFunction(getUrlParam('CKEditorCleanUpFuncNum')); |
570
|
|
|
} |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
function useFckeditor2(url) { |
574
|
|
|
if (!usingFckeditor2()) { return; } |
575
|
|
|
|
576
|
|
|
var p = url; |
577
|
|
|
var w = data['Properties']['Width']; |
|
|
|
|
578
|
|
|
var h = data['Properties']['Height']; |
579
|
|
|
window.opener.SetUrl(p,w,h); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
var url = items[0].url; |
583
|
|
|
var callback = getUrlParam('callback'); |
584
|
|
|
var useFileSucceeded = true; |
585
|
|
|
|
586
|
|
|
if (usingWysiwygEditor()) { |
587
|
|
|
useTinymce3(url); |
588
|
|
|
|
589
|
|
|
useTinymce4AndColorbox(url); |
590
|
|
|
|
591
|
|
|
useCkeditor3(url); |
592
|
|
|
|
593
|
|
|
useFckeditor2(url); |
594
|
|
|
} else if (callback && window[callback]) { |
595
|
|
|
window[callback](getSelectedItems()); |
596
|
|
|
} else if (callback && parent[callback]) { |
|
|
|
|
597
|
|
|
parent[callback](getSelecteditems()); |
598
|
|
|
} else if (window.opener) { // standalone button or other situations |
599
|
|
|
window.opener.SetUrl(getSelectedItems()); |
600
|
|
|
} else { |
601
|
|
|
useFileSucceeded = false; |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
if (useFileSucceeded) { |
605
|
|
|
if (window.opener) { |
606
|
|
|
window.close(); |
607
|
|
|
} |
608
|
|
|
} else { |
609
|
|
|
console.log('window.opener not found'); |
|
|
|
|
610
|
|
|
// No editor found, open/download file using browser's default method |
611
|
|
|
window.open(url); |
612
|
|
|
} |
613
|
|
|
} |
614
|
|
|
//end useFile |
615
|
|
|
|
616
|
|
|
// ================================== |
617
|
|
|
// == WYSIWYG Editors Check == |
618
|
|
|
// ================================== |
619
|
|
|
|
620
|
|
|
function usingTinymce3() { |
621
|
|
|
return !!window.tinyMCEPopup; |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
function usingTinymce4AndColorbox() { |
625
|
|
|
return !!getUrlParam('field_name'); |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
function usingCkeditor3() { |
629
|
|
|
return !!getUrlParam('CKEditor') || !!getUrlParam('CKEditorCleanUpFuncNum'); |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
function usingFckeditor2() { |
633
|
|
|
return window.opener && typeof data != 'undefined' && data['Properties']['Width'] != ''; |
|
|
|
|
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
function usingWysiwygEditor() { |
637
|
|
|
return usingTinymce3() || usingTinymce4AndColorbox() || usingCkeditor3() || usingFckeditor2(); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
// ================================== |
641
|
|
|
// == Others == |
642
|
|
|
// ================================== |
643
|
|
|
|
644
|
|
|
function defaultParameters() { |
645
|
|
|
return { |
646
|
|
|
working_dir: $('#working_dir').val(), |
647
|
|
|
type: $('#type').val() |
648
|
|
|
}; |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
function notImp() { |
652
|
|
|
notify('Not yet implemented!'); |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
function notify(body, callback) { |
656
|
|
|
$('#notify').find('.btn-primary').toggle(callback !== undefined); |
657
|
|
|
$('#notify').find('.btn-primary').unbind().click(callback); |
658
|
|
|
$('#notify').modal('show').find('.modal-body').html(body); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
function dialog(title, value, callback) { |
662
|
|
|
$('#dialog').find('input').val(value); |
663
|
|
|
$('#dialog').on('shown.bs.modal', function () { |
664
|
|
|
$('#dialog').find('input').focus(); |
665
|
|
|
}); |
666
|
|
|
$('#dialog').find('.btn-primary').unbind().click(function (e) { |
|
|
|
|
667
|
|
|
callback($('#dialog').find('input').val()); |
668
|
|
|
}); |
669
|
|
|
$('#dialog').modal('show').find('.modal-title').text(title); |
670
|
|
|
} |
671
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.